package com.jpa_demo;


import com.jpa_demo.entity.User;
import com.jpa_demo.repositories.UserRepository;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;


import java.util.List;
import java.util.Optional;

@ComponentScan
public class Main {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Main.class);
//        UserService bean = context.getBean(UserService.class);
        UserRepository bean = context.getBean(UserRepository.class);
        List<User> all = bean.findAll((root, query, criteriaBuilder) ->{
            //root 差不等于 from
            Root<User> from = query.from(User.class);
            Path<String> name = root.get("name");
            Predicate like = criteriaBuilder.like(name, "贝尔格里尔斯%");
            return like;
        });

        all.forEach(System.out::println);

    }


}
